package com.h3bpm.web.instance.projectWrittenFiling;

import com.alibaba.fastjson.JSONObject;
import com.h3bpm.web.common.utils.SqlUtil;
import com.h3bpm.web.instance.applicationAgencyNo.ApplicationAgencyNoController;
import com.h3bpm.web.util.DateUtil;
import data.DataRow;
import data.DataTable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 项目书面档案归档申请表
 */
@RestController
@RequestMapping("/Portal/Instances")
public class ProjectWrittenFilingController {

    private static final Logger logger = LoggerFactory.getLogger(ProjectWrittenFilingController.class);
    @RequestMapping("/getFileNo")
    public JSONObject getReportNo(){
        logger.info("获取归档编号————————————————-");
        JSONObject result = new JSONObject();
        try {
            String biddingAgencyNo="";
            String newBiddingAgencyNo="";
            Integer no=0;
            String sql="select fileNo from i_projectWrittenFiling ORDER BY CreatedTime desc LIMIT 1";
            DataTable data = null;
            data = SqlUtil.doQuery(sql);
            List<DataRow> entityRows = data.getEntityRows();
            if(!entityRows.isEmpty()&&entityRows.size()>0) {
                biddingAgencyNo = entityRows.get(0).getString("fileNo");
            }
            if(StringUtils.isNotBlank(biddingAgencyNo)){
                if(biddingAgencyNo.length()>5){
                    newBiddingAgencyNo=biddingAgencyNo.substring(biddingAgencyNo.length()-5);
                }
            }
            if(StringUtils.isNotBlank(newBiddingAgencyNo)){
                no=Integer.parseInt(newBiddingAgencyNo);
            }
            no=no+1;
            String str = "10000" + no.toString();
            str = str.substring(str.length() - 5);
            str = "F0102-"+str;
            logger.info("获取招标代理号—————————str———————-"+str);
            result.put("state", "200");
            result.put("data", str);
            result.put("msg", "success");
            return result;
        } catch (Exception e) {
            e.printStackTrace();

        }
        return  null;
    }
}
